package com.shop.service.impl;

import com.shop.entity.Privilege;
import com.shop.mapper.PrivilegeMapper;
import com.shop.service.PrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("privilegeService")
public class PrivilegeServiceImpl implements PrivilegeService {

    @Autowired
    PrivilegeMapper privilegeMapper;

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int add(Privilege privilege) throws Exception {
        int add =0;
        try {
            add=privilegeMapper.add(privilege);
        } catch (Exception e) {
            throw  new Exception("添加异常！");
        }
        return add;
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int update(Privilege privilege) throws Exception {
        try {
            int update = privilegeMapper.update(privilege);
            return update;
        } catch (Exception e) {
            throw  new Exception("更新异常！");
        }

    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public int del(Privilege privilege) throws Exception {
        try {
            int del = privilegeMapper.del(privilege);
            return del;
        } catch (Exception e) {
            throw  new Exception("删除异常！");
        }

    }

    @Override
    public Privilege get(Privilege privilege) {
        return privilegeMapper.get(privilege);
    }

    @Override
    public List<Privilege> getList(Privilege privilege) {
        return privilegeMapper.getList(privilege);
    }
}
